#import "CoinCount.h"



@implementation CoinCount

@synthesize pCount;
@synthesize nCount;
@synthesize dCount;
@synthesize qCount;
@synthesize lCount;
@synthesize tCount;
@synthesize totalValue;
@synthesize randomNumber;
@synthesize lastValue;

//the following addxxxxx and decxxxx are used to add and take away coins

-(int)addPenny
{
	pCount=pCount+1;
	return  pCount;
}

-(int)decPenny;
{
	if(pCount>0) //if statement to keep the player from having a negative amount of coins
	{	pCount=pCount-1;
		return  pCount;
	}
	else
	{
		return 0;
	}
}


-(int)addNickel;
{
	nCount=nCount+1;
	return  nCount;
}

-(int)decNickel;
{	
	if(nCount>0)
	{
		nCount=nCount-1;
		return  nCount;
	}
	else
	{
		return 0;
	}
}


-(int)addDime;
{
	dCount=dCount+1;
	return  dCount;
}

-(int)decDime;
{
	
	if(dCount>0)
	{
		dCount=dCount-1;
		return  dCount;
	}
	else
	{
		return 0;
	}
}



-(int)addQuater;
{
	qCount=qCount+1;
	return  qCount;
}

-(int)decQuater;
{
	
	if(qCount>0)
	{
		qCount=qCount-1;
		return  qCount;
	}
	else
	{
		return 0;
	}
}

-(int)addLoonie;
{
	lCount=lCount+1;
	return  lCount;
}

-(int)decLoonie;
{
	
	if(lCount>0)
	{
		lCount=lCount-1;
		return  lCount;
	}
	else
	{
		return 0;
	}
}



-(int)addToonie;
{
	tCount=tCount+1;
	return  tCount;
}

-(int)decToonie;
{
	
	if(tCount>0)
	{
		tCount=tCount-1;
		return  tCount;
	}
	else
	{
		return 0;
	}
}



-(float)total;
{
	//total up the value of the coins
	totalValue=(pCount*0.01+nCount*0.05+dCount*0.1+qCount*0.25+lCount+tCount*2);
	
	// if randomNumber == 0  that means that the player didn't start the game yet	
	if(randomNumber==0)
	{
		return -2; 
		
	}
	else if((totalValue-randomNumber)==0)// if the'totalValue' equal the 'randomNumber' that mean the player got the correct answer
	{
		return -1;
	}
	else
	{	//if it not the other 2 cases then the player got the wrong answer
		// return what they answer
		return  totalValue;
	}
}

-(float)getquestion;
{
	return randomNumber;
}

//generate a random value

-(float)hardValue;
{
	float value1;
	
	
	value1 =arc4random()%48;
	value1=value1/100+.51;
	
	randomNumber=value1+4+arc4random()%3;
	
	if(lastValue==randomNumber) //this if statement is to keep the random number from being the same 2 time in a row, it would add 65 cent to the last value
	{
		randomNumber=randomNumber+1.21;
	}
	//set coins count to 0 
	pCount = 0;
	nCount = 0;
	dCount = 0;
	qCount = 0;
	lCount = 0;
	tCount = 0;
	lastValue=randomNumber; //update 'lastValue'
	
	
	return randomNumber; //return the value the player should be trying to get
}



-(float)randomValue;
{
	float value1;
	
	//'value' will become the cent of the random value
	value1 =arc4random() %100;
	value1=value1/100;
	randomNumber=value1+arc4random() %7+.27;// the adding .27 is for the rare case where the random value is 0
	
	if(lastValue==randomNumber) //this if statement is to keep the random number from being the same 2 time in a row, it would add 65 cent to the last value
	{
		randomNumber=randomNumber+.65;
	}
	//set coins count to 0 
	pCount = 0;
	nCount = 0;
	dCount = 0;
	qCount = 0;
	lCount = 0;
	tCount = 0;
	lastValue=randomNumber; //update 'lastValue'
	
	
	return randomNumber; //return the value the player should be trying to get
}

-(float)easierValue;
{
	
	//the randomNumber made using this function is a mulitple of .25.  It range from .25 to 6.5
	
	pCount =arc4random() %26; 
	randomNumber=pCount*.25+.25;
	
	if(randomNumber==lastValue)//if the value is the same as the last question, change it by adding 1.25 to it
	{
		randomNumber=randomNumber+1.25;
	}	
	//reset the coin count
	pCount = 0;
	nCount = 0;
	dCount = 0;
	qCount = 0;
	lCount = 0;
	tCount = 0;
	
	lastValue=randomNumber; //update the lastValue
	return randomNumber; //return the number
	
}

//this function is to make a random value that a mulitple of .1
-(float)easyValue;
{
	//the random value will range from .1 and 7.1
	dCount =arc4random() %70;
	randomNumber=dCount*.1+.1;
	
	//if the value is the same as the last value, add .7 to it
	if(lastValue==randomNumber)
	{
		randomNumber=randomNumber+.7;
	}
	//reset the coin count
	pCount = 0;
	nCount = 0;
	dCount = 0;
	qCount = 0;
	lCount = 0;
	tCount = 0;
	lastValue=randomNumber;//update the last value
	
	return randomNumber;//return the randomvalue
	
}


-init
{
	/*
	 pCount = 0;
	 nCount = 0;
	 dCount = 0;
	 qCount = 0;
	 lCount = 0;
	 tCount = 0;
	 totalValue=0;
	 randomNumber=0;
	 */
	return self;
	
}

-(void)dealloc
{
	
	[super dealloc];
}


@end
